package com.ravi;

import com.ravi.dao.CheckPlanDAO;
import com.ravi.entity.CheckGroup;
import com.ravi.entity.CheckItem;
import com.ravi.entity.CheckPlan;
import com.ravi.vo.PlanGroupVo;
import com.ravi.vo.PlanItemVo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.math.BigDecimal;
import java.util.List;

@SpringBootTest
public class CheckPlanTEST {

	@Autowired
	private CheckPlanDAO checkPlanDAO;

	@Test
	public void selectPlanGroupsByPlanIdTest() {
		PlanGroupVo planGroupVo = checkPlanDAO.selectPlanGroupVoByPlanId(1);
		System.out.println(planGroupVo.getPlanName());
		System.out.println("包含的项目有：");
		List<CheckGroup> groupList = planGroupVo.getCheckGroupList();
		groupList.forEach(checkGroup -> System.out.println(checkGroup.getGroupName() + "--" + checkGroup.getWaste()));
	}

	@Test
	public void selectCheckPlanById() {
		Integer planId = 2;
		CheckPlan checkPlan = checkPlanDAO.selectPlanById(planId);
		System.out.println(checkPlan.getPlanName());
		BigDecimal price = checkPlan.getPlanPrice();
		System.out.println(price.divide(BigDecimal.valueOf(2)));
	}

	@Test
	public void selectPlanItemListTest() {
		Integer planId = 1;
		PlanItemVo planItemVo = checkPlanDAO.selectPlanItemListById(planId);
		if (planItemVo == null) {
			System.out.println("null");
			return;
		}
		List<CheckItem> checkItemList = planItemVo.getCheckItemList();
		System.out.println(planItemVo.getPlanName());
		for (CheckItem item : checkItemList) {
			System.out.println(item.getItemName());
		}
	}

	@Test
	public void selectGroupListTest() {
		Integer planId = 2;
		List<CheckGroup> checkGroupList = checkPlanDAO.selectPlanGroupListById(planId);
		if (checkGroupList.isEmpty()) {
			System.out.println("非法套餐！");
			return;
		}
		for (CheckGroup checkGroup : checkGroupList) {
			System.out.println(checkGroup.getGroupName());
		}
	}
}
